import type {
  GetOrderBuyNowParams,
  GetOrderListParams,
  OrderInfo,
  OrderListResult,
  OrderLogisticResult,
  OrderResult,
  postOrderParams,
} from '@/types/order'
import { http } from '@/utils/http'
/**
 * 获取预付订单信息(购物车中选中商品信息)的接口方法
 */
export const getOrderPreInfoAPI = () => http.get<OrderInfo>('/member/order/pre')
/**
 * 获取立即购买订单信息的接口方法
 * @param query{skuID,count,addressId?}
 */
export const getOrderBuyNowInfoAPI = (query: GetOrderBuyNowParams) =>
  http.get<OrderInfo>('/member/order/pre/now', query)
/**
 * 获取再次购买商品数据的接口方法
 * @param id 订单id
 */
export const getOrderBuyAgainInfoAPI = (id: string) =>
  http.get<OrderInfo>(`/member/order/repurchase/${id}`)
/**
 * 提交订单的接口方法
 * @param data 请求参数(body)
 * @returns 订单id
 */
export const postOrderAPI = (data: postOrderParams) =>
  http.post<{ id: string }>('/member/order', data)
/**
 * 获取订单详情的接口方法
 * @param id 订单id
 * @returns 订单详情
 */
export const getOrderDetailAPI = (id: string) =>
  http.get<OrderResult>(`/member/order/${id}`)
/**
 * 取消订单的接口方法
 * @param id(path)  订单id
 * @param data(body)  取消理由
 */
export const cancelOrderAPI = (id: string, data: { cancelReason: string }) =>
  http.put(`/member/order/${id}/cancel`, data)
/**
 * 生产环境/开发环境模拟获取微信支付参数接口方法
 * @param orderId 订单id
 */
export const getWeMiniPayOrMockAPI = (orderId: string) =>
  import.meta.env.DEV
    ? http.get<{ msg: string }>('/pay/mock', { orderId })
    : http.get<WechatMiniprogram.RequestPaymentOption>('/pay/wxPay/miniPay', {
        orderId,
      })
/**
 * 模拟订单发货接口方法 在DEV环境中使用仅且订单状态必须为待发货,调用后订单状态修改为待收货,包含模拟物流
 * @param id 订单id
 */
export const getMockDeliverAPI = (id: string) =>
  http.get(`/member/order/consignment/${id}`)
/**
 * 确认收货接口方法
 * @param id
 * @returns 订单详情
 */
export const confirmReceiptAPI = (id: string) =>
  http.put<OrderResult>(`/member/order/${id}/receipt`)
/**
 * 获取订单物流
 * @description 仅在订单状态为待收货，待评价，已完成时，可获取物流信息。
 * @param id 订单id
 * @returns 物流信息
 */
export const getOrderLogisticsAPI = (id: string) =>
  http.get<OrderLogisticResult>(`/member/order/${id}/logistics`)
/**
 * 删除订单接口方法
 * @description 仅在订单状态为待评价，已完成，已取消时，可删除订单。
 * @param data 订单id集合
 */
export const deleteOrderAPI = (data: { ids: string[] }) =>
  http.delete('/member/order', data)
/**
 * 获取订单列表的接口方法
 * @param query (请求query参数)
 * @returns 订单列表数据
 */
export const getOrderListAPI = (query?: GetOrderListParams) =>
  http.get<OrderListResult>('/member/order', query)
